<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        
        <link rel="stylesheet" type="text/css" href="style3.css" />
    </head>
    <body>

        <?php
        // Connecting to the database
        error_reporting(E_ALL ^ E_NOTICE);
        $conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
        mysql_select_db("mydb", $conn) or die(mysql_error());
        ?>
        <script type="text/javascript">
              window.alert("Please enter your information first");
        </script>
        <?php
        // listing the entries that will be posted to the db
        if ($_POST['submit']) {

            $id = $_GET['member_id'];
            $first_name = $_POST['first_name'];
            $last_name = $_POST['last_name'];
            $phoneNum = $_POST['phoneNum'];
            $fax = $_POST['fax'];
            $address = $_POST['address'];
            $affiliation = $_POST['affiliation'];
            $fb_page = $_POST['fb_page'];
            $linked_page = $_POST['linked_page'];
            $website = $_POST['website'];
            $research_gate_site = $_POST['research_gate_site'];
            $academic_site = $_POST['academic_site'];
            $mendeley_site = $_POST['mendeley_site'];


            // Selecting all information from table member where the member_id is equal to the users id 
            $checkUserQuery = mysql_query("SELECT * FROM member WHERE member_id ='$id'");



            // It's obligatory to write the first name and last name
            if (!$first_name OR !$last_name) {
                echo "<script> alert('Please make sure you entered all required data indictaed by the * sign');</script>";
            }


            // If the selected id was previously on the db, then update these entries
            if (mysql_num_rows($checkUserQuery) > 0) {
                $query = mysql_query("UPDATE member SET first_name = '$first_name', 
                       last_name = '$last_name', phoneNum = '$phoneNum',
                       fax = '$fax', address = '$address', affiliation = '$affiliation',
                       fb_page = '$fb_page', linked_page = '$linked_page',
                       website = '$website', research_gate_site = '$research_gate_site',
                       academic_site = '$academic_site', mendeley_site = '$mendeley_site'
                       WHERE member_id = '$id'");
                //Email Counter
                $x = 0;
                //Max emails = 19
                while ($x < 19) {
                    $email = 'email';
                    //Append Email Number
                    $email = $email . $x;
                    //Get Data from $_Post
                    $email2 = $_POST[$email];
                    //Check that feild ! empty
                    if ($email2 != null) {
                        //Selecting any email equivelant to the one the user entered
                        $if_exists = mysql_query("SELECT m.email, e.email FROM member m , emails e WHERE (e.email = '$email2')OR(m.email = '$email2')");
                        //initializing the number of rows with zero
                        $num_of_rows = 0;
                        // while there's is an equivlenet email, increment the num_of_rows
                        while ($row = mysql_fetch_assoc($if_exists)) {
                            $num_of_rows++;
                        }
                        //Checking if that email was not in use
                        if ($num_of_rows == 0) {

                            //insert the id and email in the database
                            $query = mysql_query("INSERT INTO emails VALUES ('$id', '$email2')");
                        } else {
                            ?>

                            <script type="text/javascript">
                                // Alert to the user that the email entered is already in use
                                window.alert("<?php echo $email2;
                    ?> is already in use")
                            </script>
                            <?php
                        }

                    }
                    //Increment Counter
                    $x = $x + 1;
                }
                ?>
                <script type="text/javascript">
                    window.alert("Done");
        <?php
        //getting the data from conferencePage and incoming requests
        $from_url = $_GET['from'];
          // get the member_id sent from the previous page (incomingRequests.php)
    $member_id = $_GET['member_id'];
    // get the conference id sent from the previous page (incomingRequests.php)
    $confid = $_GET['conference_id'];
    // get the request id sent from the previous page (incomingRequests.php)
    $request_id = $_GET['request_id'];
        //if data == A
        if ($from_url == 'A') {
            //redirect on the submission page
        header("Location: submission.php?conference_id={$confid}&member_id={$member_id}");

           // if data == B
        } else if ($from_url == 'B') {
            //redirect on the main page
          header("Location:userHomePage.php");

        }// if data == C
        else if ($from_url == 'C'){
            //redirect on the submission page with the request_id      header("Location: Submission.php?from=A&conference_id={$confid}&member_id={$member_id}&request_id={$request_id}&new='1'");

      header("Location: Submission.php?from=A&conference_id={$confid}&member_id={$member_id}&request_id={$request_id}&new='1'");

        ?>
                </script>
                <?php
            }
        }
        }
// Closing connection
        mysql_close($conn);
        ?>

        <form method="post" action="SignUp.php?from=<?php echo $_GET['from'] ?>&member_id=<?php echo $_GET['member_id'] ?>&conference_id=<?php echo $_GET['conference_id'] ?>&request_id=<?php echo $_GET['request_id'] ?>">
            <table>
                <tr><td>*First name:<input type="text" name="first_name" 
                                           id="txtChar" onkeypress="return lettersOnly(event)"/><br /></td></tr>
                <tr><td>*Last name:<input type="text" name="last_name" 
                                          id="txtChar" onkeypress="return lettersOnly(event)"/><br /></td></tr>
                <tr><td>Phone Number:<input type="text" name="phoneNum" 
                                            id="txtChar" onkeypress="return isNumberKey(event)"/><br /></td></tr>
                <tr><td>Fax:<input type="text" name="fax"  
                                   id="txtChar" onkeypress="return isNumberKey(event)"/><br /></td></tr>
                <tr><td>Address:<input type="text" name="address" /><br /></td></tr>
                <tr><td>Affiliation:<input type="text" name="affiliation" /><br /></td></tr>
                <tr><td>Facebook Page:<input type="url" name="fb_page" /><br /></td></tr>
                <tr><td>Linked Page:<input type="url" name="linked_page" /><br /></td></tr>
                <tr><td>Web-site:<input type="url" name="website" /><br /></td></tr>
                <tr><td>Research Gate Site:<input type="url" name="research_gate_site" /><br /></td></tr>
                <tr><td>Academic Site:<input type="url" name="academic_site" /><br /></td></tr>
                <tr><td>Mendeley Site:<input type="url" name="mendeley_site" /><br /></td></tr>
                <tr><td>
                        <SELECT name="element" hidden="true">
                            <OPTION value="email"></OPTION>
                        </SELECT>
                        <INPUT type="button" value="Add Extra Email" onclick="add(document.forms[0].element.value)"/>
                        <span id="fooBar">&nbsp;</span>
                        </br>
                    </td>
                </tr>
                <tr><th>
                        <input type="submit" name="submit" value="Submit" /></th>
                </tr>
            </table>
        </form>
    </body>
</html>
<head>
    <script src="sysJavascript.js" language="javascript">
    </script>
</head>
